/*
 * VistaReservasPaquetes.java
 *
 * Created on 26 de noviembre de 2008, 11:27 PM
 */

package ddta;

import java.util.ArrayList;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author  julio
 */
public class VistaReservasPaquetes extends JDialog {
    private DDTA ddta;
    private DefaultTableModel tableModel;
    private ArrayList<Turista> turistas;
    private int numeroPaquetes = 0;
    /** Creates new form VistaReservasPaquetes */
    public VistaReservasPaquetes(JDialog parent, boolean modal, DDTA ddta, String codAgencia) {
        super(parent, modal);
        initComponents();
        this.ddta = ddta;
        this.tableModel = (DefaultTableModel) tblTuristas.getModel();
        this.turistas = new ArrayList<Turista>();
        mostrarPaquetes(codAgencia);
        mostrarAgencia(codAgencia);
        this.numeroPaquetes = 0;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
   @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnGuardar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cboTipoPersona = new javax.swing.JComboBox();
        txtCodCliente = new javax.swing.JTextField();
        txtNomCliente = new javax.swing.JTextField();
        btnAddCliente = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblTuristas = new javax.swing.JTable();
        btnAddTurista = new javax.swing.JButton();
        btnQuitarTurista = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtMontoPagar = new javax.swing.JTextField();
        txtNumeroPaquetes = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtcodBoleta = new javax.swing.JTextField();
        btnPaquetes = new javax.swing.JButton();
        cboPaquete = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        txtCodAgencia = new javax.swing.JTextField();
        txtAgencia = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Reserva de paquetes");

        btnGuardar.setText("  Guardar boleta  ");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnCancelar.setText("   Cancelar   ");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de la venta"));

        jLabel1.setText("Titular :");

        cboTipoPersona.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Persona", "Empresa" }));
        cboTipoPersona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboTipoPersonaActionPerformed(evt);
            }
        });

        txtCodCliente.setEditable(false);

        txtNomCliente.setEditable(false);

        btnAddCliente.setText("Clientes...  ");
        btnAddCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddClienteActionPerformed(evt);
            }
        });

        jLabel2.setText("Paquete turistico :");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Detalle de turistas"));

        tblTuristas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Nombre", "Nacionalidad", "Edad", "Monto"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblTuristas);
        tblTuristas.getColumnModel().getColumn(0).setPreferredWidth(30);
        tblTuristas.getColumnModel().getColumn(1).setPreferredWidth(150);
        tblTuristas.getColumnModel().getColumn(3).setPreferredWidth(25);
        tblTuristas.getColumnModel().getColumn(4).setPreferredWidth(40);

        btnAddTurista.setText("Agregar turista...");
        btnAddTurista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddTuristaActionPerformed(evt);
            }
        });

        btnQuitarTurista.setText("  Quitar turista  ");
        btnQuitarTurista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnQuitarTuristaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 754, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnAddTurista)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnQuitarTurista)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(14, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnQuitarTurista)
                    .addComponent(btnAddTurista))
                .addGap(82, 82, 82))
        );

        jLabel3.setText("Numero de paquetes :");

        jLabel4.setText("Total a pagar :");

        txtMontoPagar.setEditable(false);
        txtMontoPagar.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtMontoPagar.setText("0.0");

        txtNumeroPaquetes.setEditable(false);
        txtNumeroPaquetes.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtNumeroPaquetes.setText("0");

        jLabel5.setText("Código Operación :");

        btnPaquetes.setText("Paquetes...");
        btnPaquetes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPaquetesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel5))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtcodBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(cboPaquete, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                            .addComponent(cboTipoPersona, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(txtCodCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(txtNomCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(btnPaquetes)
                                        .addComponent(btnAddCliente))))
                            .addGap(45, 45, 45))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel3)
                                .addComponent(jLabel4))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtNumeroPaquetes)
                                .addComponent(txtMontoPagar, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtcodBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCodCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAddCliente)
                    .addComponent(jLabel1)
                    .addComponent(txtNomCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboTipoPersona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cboPaquete, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPaquetes))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtNumeroPaquetes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtMontoPagar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(86, 86, 86))
        );

        jLabel6.setText("Agencia :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCodAgencia, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtAgencia, javax.swing.GroupLayout.PREFERRED_SIZE, 514, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancelar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtCodAgencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtAgencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 495, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnGuardar))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnAddTuristaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddTuristaActionPerformed
// TODO add your handling code here:
    VistaAddTurista frmAddTurista = new VistaAddTurista(this, true, this.ddta);
    frmAddTurista.setVisible(true);
    Turista turista = frmAddTurista.retornarTurista();
    if (turista != null) {
        this.turistas.add(turista);
        mostrarCalcurarTarifas();
    }
    frmAddTurista.dispose();
}//GEN-LAST:event_btnAddTuristaActionPerformed

private void btnAddClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddClienteActionPerformed
// TODO add your handling code here:
    JDialog frmCliente;
    String nomCliente = "", codCliente = "";
    String tipoPersona = cboTipoPersona.getSelectedItem().toString();
    if (tipoPersona.equals("Persona")) {
        frmCliente = new VistaClientePersona(this, true, this.ddta);
    } else {
        frmCliente = new VistaClienteEmpresa(this, true, this.ddta);
    }
    frmCliente.setVisible(true);
    if (tipoPersona.equals("Persona")) {
        ClientePersona persona = (ClientePersona)((VistaClientePersona)frmCliente).retornarCliente();
        if (persona != null) {
            nomCliente = persona.getNombre();
            codCliente = persona.getCodigoCliente();
        } else {
            return;
        }
    } else {
        ClienteEmpresa persona = (ClienteEmpresa)((VistaClienteEmpresa)frmCliente).retornarCliente();
        if (persona != null) {
            nomCliente = persona.getRazonSocial();
            codCliente = persona.getCodigoCliente();
        } else {
            return;
        }
    }
    txtCodCliente.setText(codCliente);
    txtNomCliente.setText(nomCliente);
    mostrarCalcurarTarifas();
}//GEN-LAST:event_btnAddClienteActionPerformed

private void cboTipoPersonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboTipoPersonaActionPerformed
// TODO add your handling code here:
    txtCodCliente.setText("");
    txtNomCliente.setText("");
    mostrarCalcurarTarifas();
}//GEN-LAST:event_cboTipoPersonaActionPerformed

private void btnQuitarTuristaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitarTuristaActionPerformed
// TODO add your handling code here:
    int iRow = tblTuristas.getSelectedRow();
    if (iRow >= 0) {
        String codTur = tableModel.getValueAt(iRow, 0).toString();
        removerDetalleTurista(codTur);
        mostrarCalcurarTarifas();
    } else {
        JOptionPane.showMessageDialog(this, "Seleccione un item a quitar");
    }
}//GEN-LAST:event_btnQuitarTuristaActionPerformed

private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
// TODO add your handling code here:
    this.setVisible(false);
}//GEN-LAST:event_btnCancelarActionPerformed

private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
// TODO add your handling code here:
    String codBoleta = txtcodBoleta.getText();
    String tipoCliente = cboTipoPersona.getSelectedItem().toString();
    String codCliente = txtCodCliente.getText();
    Cliente cliente = this.ddta.getCtlClientes().buscarCliente(codCliente);
    PaqueteTour paquete = (PaqueteTour)cboPaquete.getSelectedItem();
    double montoTotal = Double.parseDouble(this.txtMontoPagar.getText());
    if (!codBoleta.equals("") && !tipoCliente.equals("") && !codCliente.equals("") && cliente != null && paquete != null) {
        if (this.numeroPaquetes > 0) {
            this.ddta.getCtlVentasPaquetes().registrarVenta(codBoleta, tipoCliente, cliente, this.numeroPaquetes, montoTotal, paquete, this.turistas);
            JOptionPane.showMessageDialog(this, "Venta realizada");
            this.setVisible(false);
            enviarDatos();
        } else {
            JOptionPane.showMessageDialog(this, "Debe registrar al menos un turista");
        }
    } else {
        JOptionPane.showMessageDialog(this, "Debe ingresar todos los datos");
    }
}//GEN-LAST:event_btnGuardarActionPerformed

private void btnPaquetesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPaquetesActionPerformed
// TODO add your handling code here:
    String codAgencia = txtCodAgencia.getText();
    VistaPaquetes frmPaquetes = new VistaPaquetes(this, true, this.ddta, codAgencia);
    frmPaquetes.setVisible(true);
}//GEN-LAST:event_btnPaquetesActionPerformed

private void mostrarAgencia(String codAgencia) {
    Agencia agencia = this.ddta.getCtlAgencias().buscarAgencia(codAgencia);
    if (agencia != null) {
        txtCodAgencia.setText(codAgencia);
        txtAgencia.setText(codAgencia);
    }
}
    /**
    * @param args the command line arguments
    */
    
    public void mostrarPaquetes(String codAgencia) {
        Agencia agencia = this.ddta.getCtlAgencias().buscarAgencia(codAgencia);
        ArrayList<PaqueteTour> paquetes = new ArrayList();
        paquetes = this.ddta.getCtlPaquetes().filtrarPaquetes(agencia);
        tblTuristas.removeAll();
        cboPaquete.removeAllItems();
        if (paquetes.size() > 0) {
            for (PaqueteTour paq : paquetes) {
             cboPaquete.addItem(paq);
            }
        }
    }
    
    public void mostrarCalcurarTarifas() {
        double montoTotal = 0;
        PaqueteTour paquete = (PaqueteTour)cboPaquete.getSelectedItem();
        this.tableModel.setNumRows(0);
        //Calcular tarifa si el titular es una persona natural
        String tipoPersona = cboTipoPersona.getSelectedItem().toString();
        String codCliente = txtCodCliente.getText();
        if (tipoPersona.equals("Persona") &&  !codCliente.equals("")) {
            ClientePersona cliente = (ClientePersona)this.ddta.getCtlClientes().buscarCliente(codCliente);
            if (cliente != null) {
                montoTotal += this.ddta.getCtlTarifas().calcularTarifa(paquete.getTarifa(), cliente.getFechaNacimiento());
                this.numeroPaquetes = 1;
            }
        } else {
             this.numeroPaquetes = 0;
        }
        if (this.turistas.size() > 0) {
            this.numeroPaquetes += this.turistas.size();
            for (Turista t : this.turistas) {
                double monto = 0.0;
                if (paquete != null) {
                    monto = this.ddta.getCtlTarifas().calcularTarifa(paquete.getTarifa(), t.getFechaNacimiento());
                }
                this.tableModel.addRow(new Object[]{
                    t.getCodigo(),
                    t.getNombre(),
                    t.getNacionalidad(),
                    t.getFechaNacimiento().getEdad(),
                    monto
                });
                montoTotal += monto;
            }
        }
        txtNumeroPaquetes.setText(String.valueOf(this.numeroPaquetes));
        txtMontoPagar.setText(String.valueOf(montoTotal));
    }
    private Turista buscarTurista(String codTur) {
        Turista turista = null;
        for (Turista tur : this.turistas) {
            if (tur.getCodigo().equals(codTur)) {
                turista = tur;
                break;
            }
        }
        return turista;
    }
    private void removerDetalleTurista(String codTur) {
        Turista t = buscarTurista(codTur);
        if (t != null) {
            this.turistas.remove(t);
        }
    }

    private void enviarDatos() {
        if (this.getParent() != null) {
            if (this.getParent() instanceof VistaAgencias) {
                ((VistaAgencias)this.getParent()).mostrarGrillaAgencias();
            }
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddCliente;
    private javax.swing.JButton btnAddTurista;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnPaquetes;
    private javax.swing.JButton btnQuitarTurista;
    private javax.swing.JComboBox cboPaquete;
    private javax.swing.JComboBox cboTipoPersona;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblTuristas;
    private javax.swing.JTextField txtAgencia;
    private javax.swing.JTextField txtCodAgencia;
    private javax.swing.JTextField txtCodCliente;
    private javax.swing.JTextField txtMontoPagar;
    private javax.swing.JTextField txtNomCliente;
    private javax.swing.JTextField txtNumeroPaquetes;
    private javax.swing.JTextField txtcodBoleta;
    // End of variables declaration//GEN-END:variables

}
